From 50a0f0240d7fef133eb5acc1bea2b1168b08e9db Mon Sep 17 00:00:00 2001 From: Factiven Date: Sun, 24 Dec 2023 13:03:54 +0700 Subject: migrate to typescript --- pages/en/anime/[...id].tsx | 336 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 336 insertions(+) create mode 100644 pages/en/anime/[...id].tsx (limited to 'pages/en/anime/[...id].tsx') diff --git a/pages/en/anime/[...id].tsx b/pages/en/anime/[...id].tsx new file mode 100644 index 0000000..42cae38 --- /dev/null +++ b/pages/en/anime/[...id].tsx @@ -0,0 +1,336 @@ +import Head from "next/head"; +import Image from "next/image"; +import { useRouter } from "next/router"; +import { useEffect, useState } from "react"; +import Content from "@/components/home/content"; +import Modal from "@/components/modal"; + +import { signIn, useSession } from "next-auth/react"; +import AniList from "@/components/media/aniList"; +import ListEditor from "@/components/listEditor"; + +import DetailTop from "@/components/anime/mobile/topSection"; +import AnimeEpisode from "@/components/anime/episode"; +import { useAniList } from "@/lib/anilist/useAnilist"; +import Footer from "@/components/shared/footer"; +import { mediaInfoQuery } from "@/lib/graphql/query"; +import MobileNav from "@/components/shared/MobileNav"; + +import pls from "@/utils/request/index"; + +import Characters from "@/components/anime/charactersCard"; +import { redis } from "@/lib/redis"; +import { toast } from "sonner"; +import { Navbar } from "@/components/shared/NavBar"; +import { AniListInfoTypes } from "types/info/AnilistInfoTypes"; + +type InfoTypes = { + info: AniListInfoTypes; + color: string; + api: string; + chapterNotFound: string; +}; + +export default function Info({ info, color, chapterNotFound }: InfoTypes) { + const { data: session }: any = useSession(); + const { getUserLists } = useAniList(session); + + const [loading, setLoading] = useState(false); + const [progress, setProgress] = useState(0); + const [statuses, setStatuses] = useState(null); + const [domainUrl, setDomainUrl] = useState(""); + const [watch, setWatch] = useState(); + + const [open, setOpen] = useState(false); + const { id } = useRouter().query; + + const rec = info?.recommendations?.nodes?.map( + (data) => data.mediaRecommendation + ); + + useEffect(() => { + if (chapterNotFound) { + toast.error("Source not found"); + const cleanUrl = window.location.origin + window.location.pathname; + window.history.replaceState(null, "", cleanUrl); + } + }, [chapterNotFound]); + + useEffect(() => { + handleClose(); + async function fetchData() { + setLoading(true); + if (id) { + try { + setDomainUrl(window.location.origin); + + setProgress(0); + setStatuses(null); + + if (session?.user?.name) { + const res = await getUserLists(info.id); + const user = res?.data?.Media?.mediaListEntry; + + if (user) { + setProgress(user.progress); + const statusMapping: { + [key: string]: { name: string; value: string }; + } = { + CURRENT: { name: "Watching", value: "CURRENT" }, + PLANNING: { name: "Plan to watch", value: "PLANNING" }, + COMPLETED: { name: "Completed", value: "COMPLETED" }, + DROPPED: { name: "Dropped", value: "DROPPED" }, + PAUSED: { name: "Paused", value: "PAUSED" }, + REPEATING: { name: "Rewatching", value: "REPEATING" }, + }; + setStatuses(statusMapping[user.status]); + } + } + } catch (error) { + console.error(error); + } finally { + setLoading(false); + } + } + } + fetchData(); + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [id, info, session?.user?.name]); + + function handleOpen() { + setOpen(true); + document.body.style.overflow = "hidden"; + } + + function handleClose() { + setOpen(false); + document.body.style.overflow = "auto"; + } + + return ( + <> + + + {info + ? info?.title?.romaji || info?.title?.english + : "Retrieving Data..."} + + + + + + + + + + handleClose()}> +
+ {!session && ( +
+
+ Edit your list +
+ +
+ )} + {session && info && ( + + )} +
+
+ +
+
+
+ {info?.bannerImage && ( + banner anime + )} +
+
+ + + + + {info?.characters?.edges && ( +
+ {/*
+ ad banner +
*/} + +
+ )} + + {info && rec?.length !== 0 && ( +
+ +
+ )} +
+
+